#include <sys/global.h>
#include <sys/interrupt.h>
#include <yonex/debug.h>
#include <string.h>
#include <yonex/types.h>
#include <sys/tss.h>

#define LOGK(fmt, args...)  DEBUGK(fmt, ##args)

extern pointer_t GDT_Pointer;

/*
    gdt[0]      NULL Descriptor
    gdt[1]      kernel Code 64-bit
    gdt[2]      kernel Data 64-bit
    gdt[3]      User Code 64-bit
    gdt[4]      User Data 64-bit
    gdt[5]      kernel Code 32-bit
    gdt[6]      kernel Data 32-bit
    gdt[7]      NULL Descriptor
    gdt[8~9]    tss descriptor
    ...         NULL Descriptor
*/

void gdt_init()
{
    LOGK("init gdt\n");

    tss_init();

    // 加载GDT
    asm volatile("lgdt GDT_Pointer\n");
    // 加载TSS
    asm volatile("ltr TSS_Selector\n");
}
